import 'package:card_swiper/card_swiper.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:music_together/res/colors.dart';

import 'home_logic.dart';

class HomePage extends StatelessWidget {
  HomePage({Key? key}) : super(key: key);

  final logic = Get.find<HomeLogic>();

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: EdgeInsets.all(20.w),
        child: buildroom()
    );
  }

  Widget buildroom(){
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Expanded(
                child: Text(
                  "房间分类",
                  style: TextStyle(fontSize: 30.sp),
                )),
            GestureDetector(
              child: Text('SEE ALL'),
              onTap: () {
                /// todo 查看所有房间
              },
            )
          ],
        ),
        Container(
          height: 300.w,
          padding: EdgeInsets.only(top: 20.h),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              // IconButton(
              //   onPressed: () {
              //     logic.prePage();
              //   },
              //   icon: Icon(FluentIcons.chevron_left_med),
              // ),
              Container(
                  width: 1200.w,
                  height: 280.w,
                  child: Swiper(
                    controller: logic.swiperController,
                    itemBuilder: (context, index) {
                      return roomBuild(context, index);
                    },
                    loop:false,
                    itemCount: 5,
                    autoplayDisableOnInteraction: true,

                  )),
              IconButton(
                onPressed: () {
                  logic.nextPage();
                },
                icon: Icon(FluentIcons.chevron_right_med),
              ),
            ],
          ),
        ),



        // Flexible(
        //     child: GridView.builder(
        //         padding: EdgeInsets.only(top: 20.w),
        //         itemCount: 10,
        //         // shrinkWrap: true,
        //         gridDelegate:
        //             const SliverGridDelegateWithFixedCrossAxisCount(
        //                 crossAxisCount: 6,
        //                 mainAxisSpacing: 24,
        //                 crossAxisSpacing: 24,
        //                 childAspectRatio: 176 / 216),
        //         itemBuilder: (index, position) =>
        //             roomBuild(index, position)))
      ],
    );
  }

  Widget roomBuild(index, pos) {
    List<Widget> list = [];
    for (var index = 0; index < 6; index++) {
      list.add(GestureDetector(
          child: SizedBox(
        width: 176.w,
        height: 260.w,
        child: Container(
            width: 176.w,
            height: 260.w,
            padding: EdgeInsets.all(8.w),
            decoration: BoxDecoration(
                color: ColorStyle.colorShadow,
                borderRadius: BorderRadius.all(Radius.circular(8.w))),
            child: Column(
              children: [
                Container(
                  width: 168.w,
                  height: 168.w,
                  decoration: BoxDecoration(
                      color: ColorStyle.color_white,
                      borderRadius: BorderRadius.all(Radius.circular(8.w))),
                  child: Text(pos.toString()),
                ),
                Text("房间名称").paddingOnly(top: 10.w),
                Text(pos.toString() + "/15"),
              ],
            )),
      )));
    }

    return Wrap(
      runSpacing: 16.w,
      spacing: 16.w,
      children: list,
    );
  }
}
